package view;

import game.environments.GameEnvironment;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Image;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JTextArea;
import listener.KeyboardListener;


/**
 * Class that controls how each game environment is displayed. 
 * @author Jenni Mercado
 * 
 */

@SuppressWarnings("serial")
public class ViewController extends JFrame {
    private static final int WIDTH = 600;
    private static final int HEIGHT = 700;
    private static final String TITLE = "CS308 Game Engine";

    private Console myConsole;
    
    /**
     * Constructor that creates the frame, sets height and width, sets border.
     */
    public ViewController () {
        // set myConsole
        initializeConsole();
        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());

        // createMenuBar();
        setSize(WIDTH, HEIGHT);
        setTitle(TITLE);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        getContentPane().add(myConsole);
        setVisible(true);
    }

    /**
     * Creates a console and adds it to the frame.
     */
    public void initializeConsole () {
        myConsole = new Console();
        add(myConsole, BorderLayout.PAGE_END);
    }

    /**
     * Paints each object in the gameenvironment to the console.
     * @param ge active GameEnvironment
     */
    public void paint (GameEnvironment ge) {
        myConsole.paintLevel(ge);
    }
    /**
     * Paints image img to the console.
     * @param img background (or any kind of single image)
     */
    public void paint (Image img){
        myConsole.paint(img);
    }

    /**
     * Adds a keyboardlistener to the console
     * @param keyboardListener takes keyboard input
     */
    public void addKeyboardListener (KeyboardListener keyboardListener) {
        myConsole.addKeyListener(keyboardListener);
    }    
}
